﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CamDo.DTO;
using System.Data.SqlClient;
using System.Data;

namespace CamDo.DAO
{
    class DanhMucDAO
    {
        private DanhMuc danhMucDTO;

        internal DanhMuc DanhMucDTO
        {
            get { return danhMucDTO; }
            set { danhMucDTO = value; }
        }
        private Connect connectDTO;
        SqlConnection connect;
        String error = "";

        public String Error
        {
          get { return error; }
          set { error = value; }
        }
        public DanhMucDAO()
        {
            this.danhMucDTO = new DanhMuc();
            this.connectDTO = new Connect();
            this.connect = connectDTO.GetConnect();
        }
        public bool saveARow()
        {
            int result =0;
                
            try{
                this.connect.Open();
                String strsql = "insert into DANH_MUC(TenDM) values(";
                strsql += "'" + this.danhMucDTO.TenDanhMuc + "')";

                // String strsql = "insert into THONGTINME(MA_BN,TUANTHAI) values('100001','10')";

                SqlCommand cmd = new SqlCommand(strsql, this.connect);
                result = cmd.ExecuteNonQuery();
                this.connect.Close();
            }catch(Exception ex)
            {
                this.error = ex.ToString();
            }

            if (result <= 0)
                return false;
            return true;
                

                
        }
        public DataTable getAllData()
        {
            DataTable d = new DataTable();
            try
            {
                String sql = "SELECT *  FROM DANH_MUC";
                //String sql = "SELECT *  FROM HANG_CAM_DO";
                SqlDataAdapter da = new SqlDataAdapter(sql, this.connect);
                da.Fill(d);
            }
            catch (Exception ex)
            {
                this.error = ex.ToString();
            }
            return d;
        }
    }
}
